<template>
  <ul class="app-header-nav">
    <li class="home"><RouterLink to="/">首页</RouterLink></li>
    <li v-for="item1 in gouwuche" :key="item1.id"   @mousemove="show(item1)" @mouseleave="hide(item1)">
      <!-- 一级类目 -->
     <router-link :to="`/FenLei/${item1.id}`"  @click="hide(item1)">{{item1.name}}</router-link>
      <div class="layer" :class="{open:item1.open}">
        <ul>
          <!-- 二级类目false -->
          <li v-for="item2 in item1.children" :key="item2.id" @click="hide(item1)">
          <router-link :to="`/FenLei/ErjiZhanshi/${item2.id}`">
              <img :src="item2.picture">
              <p>{{item2.name}}</p>
          </router-link>
          </li>
        </ul>
      </div>
      </li>
  </ul>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
export default {
  name: 'AppHeaderNav',
  setup () {
    const store = useStore()
    const gouwuche = computed(() => {
      return store.state.gouwuche.gouwuche
    })
    const show = (item) => {
      store.commit('gouwuche/show', item.id)
    }
    // 关闭
    const hide = (item) => {
      store.commit('gouwuche/hide', item.id)
    }
    return { gouwuche, show, hide }
  }
}
</script>

<style scoped lang='less'>
.app-header-nav {
  width: 820px;
  display: flex;
  padding-left: 40px;
  position: relative;
  z-index: 998;
  >li {
    margin-right: 40px;
    width: 38px;
    text-align: center;
   > a {
      font-size: 16px;
      line-height: 32px;
      height: 32px;
      display: inline-block;
    }
    &:hover {
     > a {
        color: @xtxColor;
        border-bottom: 1px solid @xtxColor;
      }
    }
  }
}
.layer {
  &.open {
    height: 132px;
    opacity: 1;
  }
  width: 1240px;
  background-color: #fff;
  position: absolute;
  left: -200px;
  top: 56px;
  height: 0;
  overflow: hidden;
  opacity: 0;
  box-shadow: 0 0 5px #ccc;
  transition: all .2s .1s;
  ul {
    display: flex;
    flex-wrap: wrap;
    padding: 0 70px;
    align-items: center;
    height: 132px;
    li {
      width: 110px;
      text-align: center;
      img {
        width: 60px;
        height: 60px;
      }
      p {
        padding-top: 10px;
      }
      &:hover {
        p {
          color: @xtxColor;
        }
      }
    }
  }
}
</style>
